{extend name="./view/base/admin.html" /}
{block name="body"}
<div class="panel">
    <div class="panel-body">
        <form @submit.prevent="submit">
            <div class="form-group">
                <label>所属角色</label>
                <select v-model="form.group_id" class="form-control">
                    <option value="">请选择</option>
                    <?php foreach($group_list as $v):?>
                    <option value="{$v['id']}"><?=$v['name']?></option>
                    <?php endforeach;?>
                </select>
            </div>
            <div class="form-group">
                <label>用户名</label>
                <input class="form-control" type="text" disabled :value="form.username">
            </div>
            <div class="form-group">
                <label>上传头像</label>
                <div class="input-group">
                    <input type="text" class="form-control" v-model="form.avatar" readonly="">
                    <div class="input-group-append">
                        <input type="file" class="d-none" @change="upload">
                        <button type="button" onclick="$(this).prev('input').click()"
                            class="btn btn-yellow no-caret">上传图片</button>
                    </div>
                </div>
                <div class="input-group " v-show="form.avatar">
                    <img :src="form.avatar" class="img-responsive img-thumbnail" width="150">
                    <em class="close ml-0" title="删除这张图片" style="cursor: pointer;" onclick="deleteImage(this)">×</em>
                </div>
            </div>
            <div class="form-group">
                <label for="">登录密码</label>
                <input type="password" class="form-control" v-model="form.password">
            </div>
            <div class="form-group">
                <label for="">确认登录密码</label>
                <input type="password" class="form-control" v-model="form.rePassword">
            </div>
            <div class="form-group">
                <label>状态</label><br>
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" v-model="form.status" id="status1" value="1" />
                    <label class="form-check-label" for="status1">启用</label>
                </div>
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" v-model="form.status" id="status-1" value="-1" />
                    <label class="form-check-label" for="status-1">禁用</label>
                </div>
            </div>
            <button class="btn btn-sm btn-info" type="submit">提交</button>
        </form>
    </div>
</div>
{/block}
{block name="script"}
<script>
    new Vue({
        el:'#content',
        data(){
            return {
                form:JSON.parse('{$info|json_encode|raw}')
            }
        },
        methods: {

            upload(e) {
                var data = new FormData();
                data.append('image', e.target.files[0]);
                $.upload('{:url("upload")}', data, res => {
                    if (res.code == 0) {
                        $.alert(res);
                        return false;
                    }
                    this.form.avatar = res.data
                })
            },
            deleteImage() {
                this.form.avatar = '';
            }
        }
    })
</script>
{/block}